﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DAL;

namespace BLL
{
    public class SearchBLL
    {
        ProductDAL productDAL = new ProductDAL();
        EntityDAL entityDAL = new EntityDAL();
        CategoryBLL categoryBLL = new CategoryBLL();
        KeyBLL keyBLL = new KeyBLL();

        public SearchView Search(string keyword, SearchMode mode, List<long> categoryFilterID, List<long> keyFilterID)
        {
            SearchView view = new SearchView();

            //var categorys = categoryBLL.SeachCategoryByName(keyword, categoryFilterID).ToList();
            //var cidList = (from x in categorys select x.ID).ToList();
            //var keys = keyBLL.SeachKeyByName(keyword, keyFilterID);
            //var kidList = (from x in keys select x.ID).ToList();

            if ((mode & SearchMode.Product) == SearchMode.Product)
            {
                view.ProductList.AddRange(productDAL.GetAllByName(keyword, categoryFilterID, keyFilterID));
                //view.ProductList.AddRange(productDAL.GetAllByName(keyword, cidList, kidList));
                //view.ProductList.AddRange(productDAL.GetAllByCID(cidList));
                //view.ProductList.AddRange(productDAL.GetAllByKID(cidList));
            }
            if ((mode & SearchMode.Entity) == SearchMode.Entity)
            {
                view.EntityList.AddRange(entityDAL.GetAllByName(keyword, categoryFilterID, keyFilterID));
                //view.EntityList.AddRange(entityDAL.GetAllByName(keyword, cidList, kidList));
                //view.EntityList.AddRange(entityDAL.GetAllByCID(cidList));
                //view.EntityList.AddRange(entityDAL.GetAllByKID(cidList));
            }

            return view;
        }
    }
}
